package com.mi.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mi.bean.CustomersBean;
import com.mi.service.impl.LoginServiceImpl;
import com.mi.utils.MyUtils;

/**
 * Servlet implementation class CustomerRegisterAction
 */
@WebServlet("/CustomerRegisterAction")
public class CustomerRegisterAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 取出客户端发送的表单数据
		// 调用方法获取映射表单数据的实体类的实例
		CustomersBean customerB = MyUtils.convertFormData2Bean(request, CustomersBean.class);

		// 2、调用service层,将实体类中的数据保存到数据库中
		int i = MyUtils.getInstance(LoginServiceImpl.class).saveOrUpdateAdminInf(customerB);

		// 根据保存结果 进行页面转发
		if (i > 0) {
			// 保存成功,查询用户信息			
			String strTel = customerB.getCustomer_tel();
			request.getSession().setAttribute("stel", strTel);//session设值	
			
			request.getRequestDispatcher("loading.jsp").forward(request, response);
		} else {
			// 保存失败
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}

	}

}
